<template>
  <div class="side">
    <div class="register">
      <el-row>
        <el-button type="primary" class="dakai" @click="createData">提交</el-button>
      </el-row>
    </div>
    <div style="width:100%;margin-top:10px;">
      <el-form :model="ShareSet" label-position="right" label-width="195px" ref="dataForm">
        <!-- 退款申请 -->
        <el-form-item label="资讯分享内容">
          <el-input :rows="4" v-model="ShareSet.articleContent" style="width:450px" type="textarea"/>
          <p style="margin:0;color:#606266">变量说明：{{articleTitle}} 为资讯标题{{siteName}} 为网校名称</p>
        </el-form-item>

        <!-- 课程分享内容 -->
        <el-form-item label="课程分享内容">
          <el-input :rows="4" v-model="ShareSet.courseContent" style="width:450px" type="textarea"/>
          <p style="margin:0;color:#606266">变量说明：{{course}} 为课程名称</p>
        </el-form-item>

        <!-- 小组分享内容 -->
        <el-form-item label="小组分享内容">
          <el-input :rows="4" v-model="ShareSet.groupsContent" style="width:450px" type="textarea"/>
          <p style="margin:0;color:#606266">变量说明：{{groupName}} 为小组名称,{{threadName}} 为话题名称</p>
        </el-form-item>

        <!-- 班级分享内容 -->
        <el-form-item label="班级分享内容">
          <el-input :rows="4" v-model="ShareSet.classRoomContent" style="width:450px" type="textarea"/>
          <p style="margin:0;color:#606266">变量说明：{{classRoom}} 为班级名称</p>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
  import {addShareSetData, getShareSetData} from '@/api/system/share_set'
  import {getTenantId} from '@/utils/auth';

  export default {
    data() {
      return {
        articleTitle: '{{articleTitle}}',
        siteName: '{{siteName}}',
        course: '{{ course }}',
        groupName: '{{ groupName }}',
        threadName: '{{threadName}}',
        classRoom: '{{classRoom}}',
        ShareSet: {
          articleContent: '我正在看{{articleTitle}}，关注{{siteName}}，分享知识，成就未来。',
          courseContent: '我正在学习{{course}}，收获巨大哦，一起来学习吧！',
          groupsContent: '我在{{groupName}}小组,发表了{{threadName}},很不错哦,一起来看看吧!',
          classRoomContent: '我正在学习{{classRoom}}，收获巨大哦，一起来学习吧！'
        }
      }
    },
    created() {
      this.fetchData()
    },
    methods: {
      fetchData() {
        getShareSetData(getTenantId()).then(response => {
          this.ShareSet = response.data
        }).catch(err => {
          console.log(err)
        })
      },
      createData() {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.ShareSet.tenantId = getTenantId();
            addShareSetData(this.ShareSet).then(() => {
              this.$notify({
                title: '成功',
                message: '创建成功',
                type: 'success',
                duration: 2000
              });
             this.fetchData();
            })
          }
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
  .register {
    width: 100%;
    height: 44px;
    line-height: 44px;
    margin-left: 15px;
    padding-left: 10px;
    background-color: #e7e9ed;
    padding-top: 15px;
    padding-right: 34px;
  }

  .dakai {
    float: right;
    position: absolute;
    right: 10px;
    bottom: -25px;
  }
</style>
